#ifndef __LOS_LIST_H__
#define __LOS_LIST_H__

#ifdef __cplusplus
extern "C" {
#endif

struct los_list_t
{
    struct los_list_t *next;
};

#define los_list_init_node(node)         ((node).next = NULL)
#define los_list_insert(node, new)       ((node).next = &(new))
#define los_list_get_container(p, t, m)  container_of(p, t, m)

#define los_list_foreach(var, p, t, m) \
    for (t *var = los_list_get_container(p, t, m); var != NULL; \
            var = los_list_get_container(var->m.next, t, m))

#define los_list_foreach_next(var, n, p, t, m) \
    for (t *var = los_list_get_container(p, t, m), \
            *n = var ? los_list_get_container(var->m.next, t, m) : NULL; var != NULL; \
            var = n, n = var ? los_list_get_container(var->m.next, t, m) : NULL)

int los_list_get_length(struct los_list_t *head);
struct los_list_t *los_list_get_node(struct los_list_t *head, int idx);
int los_list_get_idx(struct los_list_t *head, struct los_list_t *node);
int los_list_is_in(struct los_list_t *head, struct los_list_t *node);
int los_list_remove(struct los_list_t **head, struct los_list_t *node);
void los_list_append(struct los_list_t *head, struct los_list_t *new_node);

#ifdef __cplusplus
}
#endif
#endif
